import { createRouter, createWebHistory } from 'vue-router'
import Register from '@/views/Register.vue'
import Login from '@/views/Login.vue'
import AdminLayout from '@/layouts/AdminLayout.vue'
import Roles from '@/views/Roles.vue'
import CounselorProfile from '@/views/CounselorProfile.vue'
import { setupRouterGuard } from './permission'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    {
      path: '/register',
      name: 'register',
      component: Register,
    },
    {
      path: '/admin',
      component: AdminLayout,
      redirect: '/admin/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'dashboard',
          component: () => import('@/views/Dashboard.vue'),
        },
        {
          path: 'users',
          name: 'users',
          component: () => import('@/views/Users.vue'),
        },
        {
          path: 'settings',
          name: 'settings',
          component: () => import('@/views/Settings.vue'),
        },
        {
          path: 'roles',
          name: 'roles',
          component: Roles,
        },
        {
          path: 'counselors',
          name: 'counselors',
          component: () => import('@/views/Counselors.vue'),
        },
        {
          path: 'appointments',
          name: 'appointments',
          component: () => import('@/views/Appointments.vue'),
        },
        {
          path: 'consultation-records',
          name: 'consultation-records',
          component: () => import('@/views/ConsultationRecords.vue'),
        },
        {
          path: 'counselor-profile',
          name: 'counselor-profile',
          component: CounselorProfile,
        },
        {
          path: 'announcements',
          name: 'announcements',
          component: () => import('@/views/Announcements.vue'),
        },
      ],
    },
  ],
})

setupRouterGuard(router)

export default router
